﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MisClient
{
    public partial class CusInputBox : Form
    {
        private Button buttonOK = new Button();
        private bool onlyNumeric;

        public CusInputBox()
        {
            InitializeComponent();
        }

        /// <summary>
        /// InputBox的静态函数，返回输入的字符串
        /// </summary>
        /// <param name="Title">窗口标题</param>
        /// <param name="Text">提示文本</param>
        /// <param name="DefaultValue">默认值</param>
        /// <returns>返回字符串</returns>
        public static string[] Input(string Title, string Code, string Name, string DefaultValue)
        {
            CusInputBox inputBox = new CusInputBox();
            inputBox.Text = Title;
            inputBox.lblCustCode.Text = Code;
            inputBox.lblCustName.Text = Name;
            DialogResult result = inputBox.ShowDialog();
            if (result == DialogResult.OK)
                return new string[] { inputBox.txtCustCode.Text, inputBox.txtCustName.Text};
            else
                return new string[] { DefaultValue };
        }

        /// <summary>
        /// InputBox的静态函数，返回输入的字符串
        /// </summary>
        /// <param name="Title">窗口标题</param>
        /// <param name="Text">提示文本</param>
        /// <param name="DefaultValue">默认值</param>
        /// <param name="OnlyNumeric">是否只允许输入数字</param>
        /// <returns>返回字符串</returns>
        public static string[] Input(string Title, string Code,string Name, string DefaultValue, bool OnlyNumeric)
        {
            CusInputBox inputBox = new CusInputBox();
            inputBox.Text = Title;
            inputBox.lblCustCode.Text = Code;
            inputBox.lblCustName.Text = Name;
            inputBox.onlyNumeric = OnlyNumeric;
            DialogResult result = inputBox.ShowDialog();
            if (result == DialogResult.OK)
                return new string[] { inputBox.txtCustCode.Text, inputBox.txtCustName.Text };
            else
                return new string[] { DefaultValue };
        }


        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void txtValue_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (onlyNumeric)
                if ((e.KeyChar < (char)Keys.D0 || e.KeyChar > (char)Keys.D9) && e.KeyChar != (char)Keys.Back)
                {
                    e.Handled = true;
                }
        }

        private void InputBox_Load(object sender, EventArgs e)
        {
            this.txtCustCode.Focus();
        }
    }
}
